//
//  MyShareJianliListVC.m
//  shortvideoplay
//
//  Created by adam on 2024/9/30.
//

#import "MyShareJianliListVC.h"
#import "MyShareJianliListCell.h"

@interface MyShareJianliListVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *listCollection;
@property (strong, nonatomic)NSMutableArray * userList;
@property (strong, nonatomic)PublicView * nullView;
@property (assign, nonatomic)NSInteger requestPage;
@end

@implementation MyShareJianliListVC

- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.frame = CGRectMake(0, 0, KScreen_W, KScreen_H-KNav_H+90-KSafeAreaBottomHeight);
    self.listCollection.backgroundColor = subviewback_black;
    self.listCollection.layer.cornerRadius = 8;
    self.listCollection.clipsToBounds = YES;
    [self.listCollection registerNib:[UINib nibWithNibName:@"MyShareJianliListCell" bundle:nil] forCellWithReuseIdentifier:@"MyShareJianliListCell"];
    self.listCollection.delegate = self;
    self.listCollection.dataSource = self;
    KWeakSelf
    self.listCollection.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        weakSelf.requestPage = weakSelf.requestPage+1;
        [weakSelf listRequest];
    }];
    self.listCollection.mj_header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        //下拉刷新要做的操作.
        [weakSelf.listCollection.mj_footer resetNoMoreData];
        [weakSelf.userList removeAllObjects];
        [weakSelf.listCollection reloadData];
        weakSelf.requestPage = 0;
        [weakSelf listRequest];
    }];
    [SVProgressHUDTool showWithStatus:nil];
    [self listRequest];
}
- (void)listRequest{
    KMutableDic(sendDic)
    sendDic[@"type"] = [NSString stringWithFormat:@"%ld",_yaoqingType+1];
    sendDic[@"page"] = [NSString stringWithFormat:@"%ld",_requestPage];
    KWeakSelf
    [YBNetBase inviteListListRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            [weakSelf.userList addObjectsFromArray:data[@"list"]];
            [weakSelf.listCollection reloadData];
        }else{
            [YBMsgPop showPop:msg];
        }
        if([weakSelf.listCollection.mj_header isRefreshing]){
            [weakSelf.listCollection.mj_header endRefreshing];
        }else if ([weakSelf.listCollection.mj_footer isRefreshing]){
            if([data[@"list"] count] == 0){
                [weakSelf.listCollection.mj_footer endRefreshingWithNoMoreData];
            }else{
                [weakSelf.listCollection.mj_footer endRefreshing];
            }
        }else{
            if(weakSelf.userList.count == 0){
                weakSelf.nullView.hidden = NO;
                weakSelf.listCollection.mj_footer.hidden = YES;
            }else{
                weakSelf.nullView.hidden = YES;
                weakSelf.listCollection.mj_footer.hidden = NO;
            }
        }
        [SVProgressHUDTool dismiss];
    }];
}
- (PublicView *)nullView{
    if(_nullView == nil){
        CGFloat h = KScreen_H-KNav_H-140-KSafeAreaBottomHeight;
        _nullView = [[PublicView alloc]initWithFrame:CGRectMake(0, (h-200)/2, KScreen_W, 200)];
        if(self.yaoqingType == 0){
            _nullView.publicLabel.text = @"还没有邀请用户，快去邀请用户吧！";
        }else{
            _nullView.publicLabel.text = @"邀请用户还没有人开通视频创作者";
        }
        
        _nullView.hidden = YES;
        _nullView.userInteractionEnabled = NO;
           UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:_nullView];
    }
    return _nullView;
}
- (NSMutableArray *)userList{
    if(_userList == nil){
        _userList = [NSMutableArray new];
    }
    return _userList;
}
#pragma mark collectionDelege
//根据item的宽度与indexPath计算每一个item的高度
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.userList.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MyShareJianliListCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyShareJianliListCell" forIndexPath:indexPath];
    cell.userDic = self.userList[indexPath.row];
    return cell;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0.0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0.0;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
 layout:(UICollectionViewLayout *)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(12, 0, 12, 0);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(KScreen_W-30, 60);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

}
#pragma mark CategoryListContentViewDelegate
- (UIView *)listView {
    return self.view;
}

@end
